package xsdcl.window;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.util.List;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.RowSpec;
import com.jgoodies.forms.factories.FormFactory;

import javax.swing.DefaultComboBoxModel;
import javax.swing.DefaultListModel;
import javax.swing.JScrollPane;
import javax.swing.JList;
import javax.swing.JButton;

import xsdcl.MS;
import xsdcl.NodeClassifier;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class OIDChooseWindow extends JFrame
{

	private JPanel contentPane;
	private JList list;
	private int result;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args)
	{
		EventQueue.invokeLater(new Runnable()
		{
			public void run()
			{
				try
				{
					OIDChooseWindow frame = new OIDChooseWindow();
					frame.setVisible(true);
				} catch (Exception e)
				{
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public OIDChooseWindow()
	{
		setTitle("Multiple Candidate OID Found");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 312);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(new FormLayout(new ColumnSpec[] {
				ColumnSpec.decode("max(63dlu;default):grow"),
				FormFactory.RELATED_GAP_COLSPEC,
				ColumnSpec.decode("default:grow"),},
			new RowSpec[] {
				FormFactory.RELATED_GAP_ROWSPEC,
				RowSpec.decode("default:grow"),
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,}));
		
		JScrollPane scrollPane = new JScrollPane();
		contentPane.add(scrollPane, "1, 2, 3, 1, fill, fill");
		
		list = new JList();
		scrollPane.setViewportView(list);
		
		JButton btnNewButton_1 = new JButton("OK");
		btnNewButton_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				result = list.getSelectedIndex();
				NodeClassifier.wait=false;
				dispose();
				
				
			}
		});
		contentPane.add(btnNewButton_1, "1, 4");
		
		JButton btnNewButton = new JButton("I'm feeling lucky...");
		contentPane.add(btnNewButton, "3, 4");
	}

	public void displayInfo(List<MS> candidateOIDList)
	{
		// TODO Auto-generated method stub
		list.setModel(new DefaultComboBoxModel(candidateOIDList.toArray()));
		
	}

	public int getResult()
	{
		// TODO Auto-generated method stub
		return 0;
	}

}
